﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Orchard;
using Bootstrap.Services;

namespace Bootstrap.Models
{
    public interface IBootstrapSetting : IDependency {
        void Describe(SettingDescriptionContext context);
    }

    public class SettingDescriptor {
        public string Name { get; set; }
        public string DisplayName { get; set; }
        public string Description { get; set; }
        public IBootstrapSettingCategory Category { get; set; }
        public int DisplayPriority { get; set; }
        public bool HasChoices { get; set; }
        public string[] Choices { get; set; }
        public bool IsSwitch { get; set; } 

        public SettingDescriptor WithDisplayName(string name) {
            DisplayName = name;
            return this;
        }

        public SettingDescriptor WithDescription(string description) {
            Description = description;
            return this;
        }

        public SettingDescriptor WithCategory(IBootstrapSettingCategory category, int displayPriority) {
            Category = category;
            DisplayPriority = displayPriority;
            return this;
        }

        public SettingDescriptor Switch() {
            IsSwitch = true;
            return this;
        }

        public SettingDescriptor WithChoices(params string[] choices) {
            HasChoices = true;
            Choices = choices;
            return this;
        }
    }

    public class SettingDescriptionContext {
        public Dictionary<string, Func<SettingDescriptor, SettingDescriptor>> Settings { get; private set; }
        public SettingDescriptionContext() {
            Settings = new Dictionary<string, Func<SettingDescriptor, SettingDescriptor>>();
        }
        public SettingDescriptionContext Describe(string name, Func<SettingDescriptor,SettingDescriptor> descriptor) {
            Settings.Add(name, descriptor);
            return this;
        }

    }
}
